package homework.exp04;

import java.util.HashMap;
import java.util.Scanner;
 
public class F {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        HashMap<String, File> fileSystem = new HashMap<>();
 
        while (scanner.hasNext()) {
            String command = scanner.next();
            if (command.equals("exit")) {
                break;
            } else if (command.equals("create")) {
                String fileName = scanner.next();
                int fileType = scanner.nextInt();
                String fileInfo = scanner.next();
                if (fileType == 0) {
                    fileSystem.put(fileName, new DataFile(fileInfo));
                } else if (fileType == 1) {
                    fileSystem.put(fileName, new Shortcut(fileInfo));
                }
            } else if (command.equals("open")) {
                String fileName = scanner.next();
                File file = fileSystem.get(fileName);
                while (file instanceof Shortcut) {
                    Shortcut shortcut = (Shortcut) file;
                    file = fileSystem.get(shortcut.getPointTo());
                }
                if (file instanceof DataFile) {
                    DataFile dataFile = (DataFile) file;
                    System.out.println(dataFile.getData());
                }
            }
        }
    }
 
    static abstract class File {
    }
 
    static class DataFile extends File {
        private String data;
 
        public DataFile(String data) {
            this.data = data;
        }
 
        public String getData() {
            return data;
        }
    }
 
    static class Shortcut extends File {
        private String pointTo;
 
        public Shortcut(String pointTo) {
            this.pointTo = pointTo;
        }
 
        public String getPointTo() {
            return pointTo;
        }
    }
}